package com.siqi.hr.system.common.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Md5加密工具类
 * @author     xiaogq
 * Created by xiaogoingqin on 2016/7/22.
 */
public class Md5Utils {

    /**
     * Md5加密(xiaogq)
     * @param plainText
     * @return
     */
    public static String Md5(String plainText) {
        if (plainText == null)
            plainText = "";
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte[] b = md.digest();
            StringBuffer buf = new StringBuffer("");
            for (int offset = 0; offset < b.length; offset++) {
                int i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

}
